package com.yellowpage.client.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.client.data.NspUserAccount;
import com.yellowpage.client.service.NspUserAccountService;

public class NspUserAccountAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<NspUserAccount> nspUserAccountList = new ArrayList<NspUserAccount>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private NspUserAccount nspUserAccount;
	private NspUserAccountService nspUserAccountService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_mobileNo;
		private String query_registTime;
		private String query_accountType;
		private String query_accountUser;
		private String query_submitter;
		private String query_submitTime;
		private String query_updateUser;
		private String query_updateTime;
		private String query_id;
		private String query_desc;
		private String query_password;
		
	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspUserAccount = nspUserAccountService.getNspUserAccount(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("mobileNo", query_mobileNo);
	    	    queryMap.put("registTime", query_registTime);
	    	    queryMap.put("accountType", query_accountType);
	    	    queryMap.put("accountUser", query_accountUser);
	    	    queryMap.put("submitter", query_submitter);
	    	    queryMap.put("submitTime", query_submitTime);
	    	    queryMap.put("updateUser", query_updateUser);
	    	    queryMap.put("updateTime", query_updateTime);
	    	    queryMap.put("id", query_id);
	    	    queryMap.put("description", query_desc);
	    	    queryMap.put("password", query_password);
	    	    	
		resultList = nspUserAccountService.queryNspUserAccountByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		nspUserAccountService.saveNspUserAccount(nspUserAccount);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    if (nspUserAccount.getMobileNo().length() == 0) {
			this.addActionError("** 用户名 不能为空 !");
		}
			    	    	    	    	    if (nspUserAccount.getAccountType().length() == 0) {
			this.addActionError("** 账户类型 不能为空 !");
		}
			    	    	    if (nspUserAccount.getAccountUser().length() == 0) {
			this.addActionError("** 账户用户名 不能为空 !");
		}
			    	    	    if (nspUserAccount.getSubmitter().length() == 0) {
			this.addActionError("** 提交者 不能为空 !");
		}
			    	    	    	    	    if (nspUserAccount.getUpdateUser().length() == 0) {
			this.addActionError("** 更新者 不能为空 !");
		}
			    	    	    	    	    	    	    if (nspUserAccount.getDescription().length() == 0) {
			this.addActionError("** 备注 不能为空 !");
		}
			    	    	    if (nspUserAccount.getPassword().length() == 0) {
			this.addActionError("** 用户密码 不能为空 !");
		}
			    	    
		this.setValidatorResult("/client/NspUserAccountAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    nspUserAccount = nspUserAccountService.getNspUserAccount(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    nspUserAccountService.updateNspUserAccount(nspUserAccount);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    if (nspUserAccount.getMobileNo().length() == 0) {
			this.addActionError("** 用户名 不能为空 !");
		}
			    			    			    if (nspUserAccount.getAccountType().length() == 0) {
			this.addActionError("** 账户类型 不能为空 !");
		}
			    			    if (nspUserAccount.getAccountUser().length() == 0) {
			this.addActionError("** 账户用户名 不能为空 !");
		}
			    			    if (nspUserAccount.getSubmitter().length() == 0) {
			this.addActionError("** 提交者 不能为空 !");
		}
			    			    			    if (nspUserAccount.getUpdateUser().length() == 0) {
			this.addActionError("** 更新者 不能为空 !");
		}
			    			    			    			    if (nspUserAccount.getDescription().length() == 0) {
			this.addActionError("** 备注 不能为空 !");
		}
			    			    if (nspUserAccount.getPassword().length() == 0) {
			this.addActionError("** 用户密码 不能为空 !");
		}
			    		this.setValidatorResult("/client/NspUserAccountUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.nspUserAccountService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲�?删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setNspUserAccount(NspUserAccount nspUserAccount) {
		this.nspUserAccount = nspUserAccount;
	}
	
	public NspUserAccount getNspUserAccount() {
		return nspUserAccount;
	}
	 
	 
	 public void setNspUserAccountService(NspUserAccountService nspUserAccountService) {
		this.nspUserAccountService = nspUserAccountService;
	}
	
	public List<NspUserAccount> getNspUserAccountList() {
		return nspUserAccountList;
	}

	public void setNspUserAccountList(List<NspUserAccount> nspUserAccountList) {
		this.nspUserAccountList = nspUserAccountList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_mobileNo() {
        return this.query_mobileNo;
    }
    
    public void setQuery_mobileNo(String mobileNo){
        this.query_mobileNo = mobileNo;
    }    

        public String getQuery_registTime() {
        return this.query_registTime;
    }
    
    public void setQuery_registTime(String registTime){
        this.query_registTime = registTime;
    }    

        public String getQuery_accountType() {
        return this.query_accountType;
    }
    
    public void setQuery_accountType(String accountType){
        this.query_accountType = accountType;
    }    

        public String getQuery_accountUser() {
        return this.query_accountUser;
    }
    
    public void setQuery_accountUser(String accountUser){
        this.query_accountUser = accountUser;
    }    

        public String getQuery_submitter() {
        return this.query_submitter;
    }
    
    public void setQuery_submitter(String submitter){
        this.query_submitter = submitter;
    }    

        public String getQuery_submitTime() {
        return this.query_submitTime;
    }
    
    public void setQuery_submitTime(String submitTime){
        this.query_submitTime = submitTime;
    }    

        public String getQuery_updateUser() {
        return this.query_updateUser;
    }
    
    public void setQuery_updateUser(String updateUser){
        this.query_updateUser = updateUser;
    }    

        public String getQuery_updateTime() {
        return this.query_updateTime;
    }
    
    public void setQuery_updateTime(String updateTime){
        this.query_updateTime = updateTime;
    }    

        public String getQuery_id() {
        return this.query_id;
    }
    
    public void setQuery_id(String id){
        this.query_id = id;
    }    

        public String getQuery_desc() {
        return this.query_desc;
    }
    
    public void setQuery_desc(String desc){
        this.query_desc = desc;
    }    

        public String getQuery_password() {
        return this.query_password;
    }
    
    public void setQuery_password(String password){
        this.query_password = password;
    }    

    
	
}
